#include "../tools.h"

class Solution {
public:
    double helper(double x, int n){
        if(n == 0) return 1.0;
        if(n == 1) return x;

        double res = helper(x, n >> 1);
        res *= res;
        if(n & 0x1 == 1) res *= x;
        return res;
    }
    double myPow(double x, int n) {
        if(x == 0) return 0;
        if(n == 0) return 1.0;
        bool flag_p = false;
        if(n < 0) {
            flag_p = true;
            n *= -1;
        }

        double res = helper(x, n);
        if(flag_p) res = 1 / res;
        return res;
    }
};

int main(int argc, char const *argv[])
{
    double x = 2.00000;
    int n = 10;
    x = 2.10000;
    n = 3;
    x = 2.00000;
    n = -2;

    Solution s;
    double res = s.myPow(x, n);


    cout << res << endl;
    
    return 0;
}
